home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / comp / lexer < prev    next >
Encoding:
Text File  |  1994-02-08  |  11.0 KB  |  325 lines

  1. %{
  2. /*
  3.                                    L E X E R
  4. */
  5.  
  6. #include "iccomp.h"
  7. #include "parser.h"
  8.  
  9. #undef  YY_INPUT
  10. #define YY_INPUT(buf,result,max_size) result = yylex_input(buf, max_size);
  11.  
  12. %}
  13.  
  14. %x str
  15.  
  16. %%
  17.  
  18. <str>[^"]   |
  19. <str>\\.                {
  20.                             strcat(string, yytext);
  21.                         }
  22. <str>\"                 {
  23.                             BEGIN 0;
  24.                             if (!stresc(string))
  25.                                 semantic("illegal escape sequence in string");
  26.                             return(STRING);
  27.                         }
  28. [ \t]                   ;
  29. \n                      yylineno++;
  30. ^#.*                    {
  31.                             change_file(yytext + 1);
  32.                         }
  33. \"                      {
  34.                             string[0] = 0; BEGIN str;
  35.                         }
  36. '.'                     {
  37.                             sprintf(string, "%d%c", yytext[1], 0);
  38.                             return(NUMBER);
  39.                         }
  40. arghead                 {
  41.                             yylval.type = f_arg_head;
  42.                             return(ARG_HEAD);
  43.                         }
  44. argtail                 {
  45.                             yylval.type = f_arg_tail;
  46.                             return(ARG_TAIL);
  47.                         }
  48. ascii                   {                   /* ascii_int may become ascii_str */
  49.                             yylval.type = f_ascii_int;
  50.                             return(ASCII);
  51.                         }
  52. break                   {
  53.                             return(BREAK);
  54.                         }
  55. chdir                   {
  56.                             yylval.type = f_chdir;
  57.                             return(CHDIR);
  58.                         }
  59. cmdtail                 {
  60.                             yylval.type = f_cmd_tail;
  61.                             return(CMD_TAIL);
  62.                         }
  63. cmdhead                 {
  64.                             yylval.type = f_cmd_head;
  65.                             return(CMD_HEAD);
  66.                         }
  67. change_base             {
  68.                             yylval.type = f_c_base;
  69.                             return(C_BASE);
  70.                         }
  71. change_ext              {
  72.                             yylval.type = f_c_ext;
  73.                             return(C_EXT);
  74.                         }
  75. change_path             {
  76.                             yylval.type = f_c_path;
  77.                             return(C_PATH);
  78.                         }
  79. fprintf                 {
  80.                             yylval.type = f_fprintf;
  81.                             return(FPRINTF);
  82.                         }
  83. get_base                {
  84.                             yylval.type = f_g_base;
  85.                             return(G_BASE);
  86.                         }
  87. get_ext                 {
  88.                             yylval.type = f_g_ext;
  89.                             return(G_EXT);
  90.                         }
  91. get_path                {
  92.                             yylval.type = f_g_path;
  93.                             return(G_PATH);
  94.                         }
  95. getch                   {
  96.                             yylval.type = f_getch;
  97.                             return(GETCH);
  98.                         }
  99. getpid                  {
  100.                             yylval.type = f_getpid;
  101.                             return(GETPID);
  102.                         }
  103. gets                    {
  104.                             yylval.type = f_gets;
  105.                             return(GETS);
  106.                         }
  107. echo                    {
  108.                             yylval.type = f_echo;
  109.                             return(M_ECHO);
  110.                         }
  111. element                 {
  112.                             yylval.type = f_element;
  113.                             return(ELEMENT);
  114.                         }
  115. else                    {
  116.                             return(ELSE);
  117.                         }
  118. exec                    {
  119.                             yylval.type = f_exec;
  120.                             return(EXEC);
  121.                         }
  122. execute                 {
  123.                             yylval.type = f_execute;
  124.                             return(EXECUTE);
  125.                         }
  126. exists                  {
  127.                             yylval.type = f_exists;
  128.                             return(EXISTS);
  129.                         }
  130. exit                    {
  131.                             yylval.type = op_exit;
  132.                             return(EXIT);
  133.                         }
  134. fgets                   {
  135.                             yylval.type = f_fgets;
  136.                             return (FGETS);
  137.                         }
  138. for                     {
  139.                             return(FOR);
  140.                         }
  141. if                      {
  142.                             return(IF);
  143.                         }
  144. void                    {
  145.                             yylval.type = 0;    /* 0 == void */
  146.                             return (VOID);
  147.                         }
  148. int                     {
  149.                             yylval.type = e_int;
  150.                             return(INT);
  151.                         }
  152. list                    {
  153.                             yylval.type = e_list;
  154.                             return(LIST);
  155.                         }
  156. makelist                {
  157.                             yylval.type = f_makelist;
  158.                             return(MAKELIST);
  159.                         }
  160. older                   {
  161.                             yylval.type = op_older;
  162.                             return(OLDER);
  163.                         }
  164. printf                  {
  165.                             yylval.type = f_printf;
  166.                             return(PRINTF);
  167.                         }
  168. putenv                  {
  169.                             yylval.type = f_putenv;
  170.                             return (PUTENV);
  171.                         }
  172. return                  {
  173.                             yylval.type = op_ret;
  174.                             return(RETURN);
  175.                         }
  176. sizeof          |
  177. sizeoflist              {
  178.                             yylval.type = f_sizeoflist;
  179.                             return(SIZEOFLIST);
  180.                         }
  181. stat                    {
  182.                             yylval.type = f_stat;
  183.                             return (STAT);
  184.                         }
  185. string                  {
  186.                             yylval.type = e_str;
  187.                             return(STRINGTYPE);
  188.                         }
  189. strlen                  {
  190.                             yylval.type = f_strlen;
  191.                             return(STRLEN);
  192.                         }
  193. strlwr                  {
  194.                             yylval.type = f_strlwr;
  195.                             return(STRLWR);
  196.                         }
  197. strupr                  {
  198.                             yylval.type = f_strupr;
  199.                             return(STRUPR);
  200.                         }
  201. strtok                  {
  202.                             yylval.type = f_fields;
  203.                             return(FIELDS);
  204.                         }
  205. substr                  {
  206.                             yylval.type = f_substr;
  207.                             return(SUBSTR);
  208.                         }
  209. system                  {
  210.                             yylval.type = f_system;
  211.                             return(SYSTEM);
  212.                         }
  213. while                   {
  214.                             return(WHILE);
  215.                         }
  216. newer   |
  217. younger                 {
  218.                             yylval.type = op_younger;
  219.                             return(YOUNGER);
  220.                         }
  221. "++"                    {
  222.                             return(INC);
  223.                         }
  224. "--"                    {
  225.                             return(DEC);
  226.                         }
  227. "/="                    {
  228.                             return(DIV_IS);
  229.                         }
  230. "-="                    {
  231.                             return(MINUS_IS);
  232.                         }
  233. "*="                    {
  234.                             return(MUL_IS);
  235.                         }
  236. "%="                    {
  237.                             return(MOD_IS);
  238.                         }
  239. "+="                    {
  240.                             return(PLUS_IS);
  241.                         }
  242. "&="                    {
  243.                             return(AND_IS);
  244.                         }
  245. "|="                    {
  246.                             return(OR_IS);
  247.                         }
  248. "^="                    {
  249.                             return(XOR_IS);
  250.                         }
  251. "<<="                   {
  252.                             return(SHL_IS);
  253.                         }
  254. ">>="                   {
  255.                             return(SHR_IS);
  256.                         }
  257. "||"                    {
  258.                             return(OR);
  259.                         }
  260. "&&"                    {
  261.                             return(AND);
  262.                         }
  263. "=="                    {
  264.                             return(EQUAL);
  265.                         }
  266. "!="                    {
  267.                             return(NOT_EQUAL);
  268.                         }
  269. "<="                    {
  270.                             return(SMALLER_EQUAL);
  271.                         }
  272. ">="                    {
  273.                             return(GREATER_EQUAL);
  274.                         }
  275. ">>"                    {
  276.                             return(SHR);
  277.                         }
  278. "<<"                    {
  279.                             return(SHL);
  280.                         }
  281. [0-9]+                  {
  282.                             strcpy(string, yytext);
  283.                             return(NUMBER);
  284.                         }
  285. OFF         |
  286. P_CHECK                 {                   /* P_CHECK: value in icm.h */
  287.                             strcpy(string, "0");
  288.                             return(NUMBER);
  289.                         }
  290. S_IFDIR     |
  291. O_FILE      |                               /* O_FILE: value in icm.h */
  292. ON                      {
  293.                             strcpy(string, "1");
  294.                             return(NUMBER);
  295.                         }
  296. S_IFCHR     |
  297. P_NOCHECK   |
  298. O_DIR                   {                   /* O_DIR: value in icm.h */
  299.                             strcpy(string, "2");
  300.                             return(NUMBER);
  301.                         }
  302. S_IFREG     |
  303. O_SUBDIR                {                   /* O_SUBDIR: value in icm.h */
  304.                             strcpy(string, "4");
  305.                             return(NUMBER);
  306.                         }
  307. S_IREAD     |
  308. O_ALL                   {                   /* O_ALL: value in icm.h */
  309.                             strcpy(string, "8");
  310.                             return(NUMBER);
  311.                         }
  312. S_IWRITE                {
  313.                             strcpy(string, "16");
  314.                             return(NUMBER);
  315.                         }
  316. S_IEXEC                 {
  317.                             strcpy(string, "32");
  318.                             return(NUMBER);
  319.                         }
  320. [_A-Za-z][A-Za-z0-9_]*  {
  321.                             strcpy(string, yytext);
  322.                             return(IDENTIFIER);
  323.                         }
  324. .                       return(yytext[0]);
  325.